#!/usr/bin/env bash


help(){
    cat<<__EOF__
Usage: m ntp [OPTION] [ARGUMENT]

Description: Manage the network time service on macOS

Options:
  --help        Show this help message
  --status      Show the current status of the network time service
  --enable      Enable the clock to use network time
  --disable     Disable the clock from using network time
  --set HOST    Set the network time server to HOST
__EOF__
}

case $1 in
    --help)
        help
        ;;
    --status)
        sudo systemsetup -getusingnetworktime
        sudo systemsetup -getnetworktimeserver 2>/dev/null
        ;;
    --enable)
        sudo systemsetup -setusingnetworktime on
        ;;
    --disable)
        sudo systemsetup -setusingnetworktime off
        ;;
    --set)
        [ -z "$2" ] && help && exit 1
        sudo systemsetup -setnetworktimeserver "$2"
        ;;
    *)
        help && exit 1
        ;;
esac
